import unittest

from timacs.importers.collectl_lexpr import CollectlLexprImporter
from timacs.interfaces.metric import *


COLLECTL_LEXPR = """\
sample.time 1246457548.001
lusclt.reads 0
lusclt.readkbs 0
lusclt.writes 0
lusclt.writekbs 0
lusclt.numfs 1
lusclt.close 0
lusclt.getattr 0
lusclt.reint 0
lusclt.sync 0
Use of uninitialized value in division (/) at /opt/hp/collectl/sbin/lexpr.ph line 118.
sample.time 1246457549.002
lusclt.reads 0
lusclt.readkbs 0
lusclt.writes 0
lusclt.writekbs 0
lusclt.numfs 1
lusclt.close 0
lusclt.getattr 0
lusclt.reint 0
"""


class CollectlLexprImporterTest(unittest.TestCase):
    def runTest( self ):
        importer = CollectlLexprImporter()
        requests = [request for request in importer._parseCollectlLexpr( COLLECTL_LEXPR )]
        assert len( requests ) == 34
        for request in requests:
            assert isinstance( request, addMetricRequest ) or \
                   isinstance( request, addMetricValueRequest ) 
        
        
suite = unittest.TestSuite()
suite.addTest( CollectlLexprImporterTest() )
